package com.miyake.loveviewweb.shared.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.google.appengine.api.datastore.Key;
import org.slim3.datastore.Attribute;
import org.slim3.datastore.Model;

@Model(schemaVersion = 1)
public class ChartModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Attribute(primaryKey = true)
    private Key key;

    @Attribute(version = true)
    private Long version;

    /**
     * Returns the key.
     *
     * @return the key
     */
    public Key getKey() {
        return key;
    }

    /**
     * Sets the key.
     *
     * @param key
     *            the key
     */
    public void setKey(Key key) {
        this.key = key;
    }

    /**
     * Returns the version.
     *
     * @return the version
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version.
     *
     * @param version
     *            the version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((key == null) ? 0 : key.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        ChartModel other = (ChartModel) obj;
        if (key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!key.equals(other.key)) {
            return false;
        }
        return true;
    }
    
    public Key getParentKey() {
        return parentKey;
    }

    public void setParentKey(Key parentKey) {
        this.parentKey = parentKey;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public double[] getXarray() {
        return xarray;
    }

    public void setXarray(double[] xarray) {
        this.xarray = xarray;
    }


    public double[] getYarray() {
        return yarray;
    }

    public void setYarray(double[] yarray) {
        this.yarray = yarray;
    }


    public boolean isContent() {
        return content;
    }

    public void setContent(boolean content) {
        this.content = content;
    }

    public ChartDataType getChartDataType() {
        return chartDataType;
    }

    public void setChartDataType(ChartDataType chartDataType) {
        this.chartDataType = chartDataType;
    }

    /**
     * @return the xLabel
     */
    public String getxLabel() {
        return xLabel;
    }

    /**
     * @param xLabel the xLabel to set
     */
    public void setxLabel(String xLabel) {
        this.xLabel = xLabel;
    }

    /**
     * @return the yLabel
     */
    public String getyLabel() {
        return yLabel;
    }

    /**
     * @param yLabel the yLabel to set
     */
    public void setyLabel(String yLabel) {
        this.yLabel = yLabel;
    }


    /**
     * @return the chartWidth
     */
    public Integer getChartWidth() {
        return chartWidth;
    }

    /**
     * @param chartWidth the chartWidth to set
     */
    public void setChartWidth(Integer chartWidth) {
        this.chartWidth = chartWidth;
    }


    /**
     * @return the chartHeight
     */
    public Integer getChartHeight() {
        return chartHeight;
    }

    /**
     * @param chartHeight the chartHeight to set
     */
    public void setChartHeight(Integer chartHeight) {
        this.chartHeight = chartHeight;
    }


    /**
     * @return the chartEngine
     */
    public ChartEngine getChartEngine() {
        return chartEngine;
    }

    /**
     * @param chartEngine the chartEngine to set
     */
    public void setChartEngine(ChartEngine chartEngine) {
        this.chartEngine = chartEngine;
    }


    /**
     * @return the chartPluginKey
     */
    public Key getChartPluginKey() {
        return chartPluginKey;
    }

    /**
     * @param chartPluginKey the chartPluginKey to set
     */
    public void setChartPluginKey(Key chartPluginKey) {
        this.chartPluginKey = chartPluginKey;
    }


    /**
     * @return the chartURL
     */
    public String getChartURL() {
        return chartURL;
    }

    /**
     * @param chartURL the chartURL to set
     */
    public void setChartURL(String chartURL) {
        this.chartURL = chartURL;
    }

    
    /**
     * @return the axes
     */
    public Map<String, Key> getAxes() {
        return axes;
    }

    /**
     * @param axes the axes to set
     */
    public void setAxes(Map<String, Key> axes) {
        this.axes = axes;
    }

    @Attribute(lob = true)
    private Map<String, Key> axes = new HashMap<String, Key>(); // Column Header, DataColumnModel Key
    
    private String name;
    private Key parentKey;
    
    private Integer chartWidth = 300;
    private Integer chartHeight = 200;
    
    @Attribute(persistent = false)
    private double[] xarray;
    @Attribute(persistent = false)
    private double[] yarray;    
    @Attribute(persistent = false)
    private boolean content;
    @Attribute(persistent = false)
    private String xLabel;
    @Attribute(persistent = false)
    private String yLabel;
    @Attribute(persistent = false)
    private String chartURL;
    
    private ChartDataType chartDataType;
    public enum ChartDataType {
        Y_DATA,
        XY_DATA,
    }
    
    private ChartEngine chartEngine = ChartEngine.DEFAULT_FLASH_CHART;
    private Key chartPluginKey;
    public enum ChartEngine {
        DEFAULT_DYNAMIC_CHART,
        DEFAULT_FLASH_CHART,
        PLUGIN_CHART
    }

}
